package com.example.mobile2021606170hsy0406homework;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Main2Activity extends AppCompatActivity {

    private TextView tvMainTitle;
    private TextView tvMainAb;
    private TextView tvMainAskfor;
    private TextView tvMainA;
    private EditText edtTxtMainFigure;
    private EditText edtTxtMainFigure1;
    private TextView tvMainB;
    private Button btMainResult;
    private TextView tvMainResult;
    private EditText edtTxtMainResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
    }

    private void initView() {
        tvMainTitle = findViewById(R.id.tv_main_title);
        tvMainAb = findViewById(R.id.tv_main_ab);
        tvMainAskfor = findViewById(R.id.tv_main_askfor);
        tvMainA = findViewById(R.id.tv_main_a);
        edtTxtMainFigure = findViewById(R.id.edtTxt_main_figure);
        edtTxtMainFigure1 = findViewById(R.id.edtTxt_main_figure1);
        tvMainB = findViewById(R.id.tv_main_b);
        btMainResult = findViewById(R.id.bt_main_result);
        tvMainResult = findViewById(R.id.edtTxt_main_result);
        edtTxtMainResult = findViewById(R.id.edtTxt_main_result);
    }

    public void onClick(View view) {
        String a = edtTxtMainFigure.getText().toString();
        String b = edtTxtMainFigure1.getText().toString();

        if (a.length() == 0 || b.length() == 0) {
            Toast.makeText(Main2Activity.this, "请输入数字", Toast.LENGTH_SHORT).show();
        } else {
            int c = Integer.parseInt(a) + Integer.parseInt(b);
            edtTxtMainResult.setText(String.valueOf(c));
        }
    }
}
